<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="姓名" prop="xm">
        <el-input
          v-model="queryParams.xm"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item>
        <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary"  size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary"  size="mini" @click="filesUpload = true"  v-hasPermi="['sen:pgy:lead']">导入</el-button>
        <el-button type="primary"  size="mini" @click="excelDownload"  v-hasPermi="['sen:pgy:download']">下载</el-button>
        <el-button type="primary"  size="mini" @click="excelLevelDownload"  v-hasPermi="['sen:pgy:statistics']">下载统计</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="pgyList" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="昵称" align="center" prop="nc" />
      <el-table-column label="姓名" align="center" prop="xm" />
      <el-table-column label="证件类型" align="center" prop="zslx" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="职别" align="center" prop="leibei" />
      <el-table-column label="手机" align="center" prop="shouji" />
      <el-table-column label="街道-居委" align="center" prop="jiewei" >
         <template slot-scope="scope">
          <span ><i @click="showUpdateNeighborhooCommittee(scope.row)" class="el-icon-edit"></i>&nbsp;<span v-if="scope.row.jiewei!=null && scope.row.jiewei !=''">{{scope.row.jiewei}}</span></span>
          </template>
      </el-table-column>
      <el-table-column label="受理数" align="center" prop="sls" />
      <el-table-column label="评估数" align="center" prop="pgs" />
      <el-table-column label="待评估数" align="center" prop="dpg" />
      <el-table-column label="撤单数" align="center" prop="cdshu" />
      <el-table-column label="是否是评审员" align="center" prop="ispsy" >
             <template slot-scope="scope">
            <span style="color:blue" @click="updateIsPsy(scope.row)">{{ scope.row.ispsy == 0?"否":"是"}}</span>
          </template>
      </el-table-column>
      <el-table-column label="绑定状态" align="center" prop="bangding" >
          <template slot-scope="scope">
            <i class="el-icon-error" v-if="scope.row.bangding == 0"></i>
            <i class="el-icon-success" v-if="scope.row.bangding == 1"></i>
          </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200"> 
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sen:pgy:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-hasPermi="['sen:pgy:delete']"
            @click="handleDelete(scope.row)"
          ></el-button>
          <el-button
            size="mini"
            type="text" 
            icon="el-icon-delete" 
            v-hasPermi="['sen:pgy:unbundle']"
            @click="jieBang(scope.row)"
          >解绑</el-button>
           <el-button
            size="mini"
            type="text" 
            v-hasPermi="['sen:pgy:classstatistics']"
            @click="tongJi(scope.row)" 
          >统计等级</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="证书类型" prop="zslx">
          <el-input v-model="form.zslx" placeholder="请输入证书类型" />
        </el-form-item>
        <el-form-item label="类别" prop="leibei">
          <el-input v-model="form.leibei" placeholder="请输入类别" />
        </el-form-item>
        <el-form-item label="医保标示码" prop="ybbsm">
          <el-input v-model="form.ybbsm" placeholder="请输入医保标示码" />
        </el-form-item>
        <el-form-item label="姓名" prop="xm">
          <el-input v-model="form.xm" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-input v-model="form.sex" placeholder="性别" />
        </el-form-item>
        <el-form-item label="证件类型" prop="zjlx">
          <el-input v-model="form.zjlx" placeholder="请输入证件类型" />
        </el-form-item>
        <el-form-item label="证件号码" prop="zjhm">
          <el-input v-model="form.zjhm" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="出生年月" prop="csny">
          <el-input v-model="form.csny" placeholder="请输入出生年月" />
        </el-form-item>
        <el-form-item label="最高学历" prop="zgxl">
          <el-input v-model="form.zgxl" placeholder="请输入最高学历" />
        </el-form-item>
        <el-form-item label="评估员培训时间" prop="pgypxsj">
          <el-input v-model="form.pgypxsj" placeholder="请输入评估员培训时间" />
        </el-form-item>
        <el-form-item label="评估员资格证书编号" prop="zgzsbh">
          <el-input v-model="form.zgzsbh" placeholder="请输入评估员资格证书编号" />
        </el-form-item>
        <el-form-item label="评估员资格证书发证日期" prop="zgzsfzrq">
          <el-input v-model="form.zgzsfzrq" placeholder="请输入评估员资格证书发证日期" />
        </el-form-item>
        <el-form-item label="评估员资格证书有效期" prop="zsyxrq">
          <el-input v-model="form.zsyxrq" placeholder="请输入评估员资格证书有效期" />
        </el-form-item>
        <el-form-item label="从事医疗或护理相关专业工作年限" prop="gznx">
          <el-input v-model="form.gznx" placeholder="请输入从事医疗或护理相关专业工作年限" />
        </el-form-item>
        <el-form-item label="工作单位" prop="gzdw">
          <el-input v-model="form.gzdw" placeholder="请输入工作单位" />
        </el-form-item>
        <el-form-item label="申报单位" prop="sbdw">
          <el-input v-model="form.sbdw" placeholder="请输入申报单位" />
        </el-form-item>
        <el-form-item label="执业证书编号" prop="zyzbh">
          <el-input v-model="form.zyzbh" placeholder="请输入执业证书编号" />
        </el-form-item>
        <el-form-item label="执业证书发证日期" prop="zyzfzrq">
          <el-input v-model="form.zyzfzrq" placeholder="请输入执业证书发证日期" />
        </el-form-item>
        <el-form-item label="执业证书注册日期" prop="zyzzcrq">
          <el-input v-model="form.zyzzcrq" placeholder="请输入执业证书注册日期" />
        </el-form-item>
        <el-form-item label="执业证书注册有效期截止日" prop="zyzjzrq">
          <el-input v-model="form.zyzjzrq" placeholder="请输入执业证书注册有效期截止日" />
        </el-form-item>
        <el-form-item label="执业地点" prop="zydd">
          <el-input v-model="form.zydd" placeholder="请输入执业地点" />
        </el-form-item>
        <el-form-item label="医师级别" prop="ysjb">
          <el-input v-model="form.ysjb" placeholder="请输入医师级别" />
        </el-form-item>
        <el-form-item label="执业范围" prop="zyfw">
          <el-input v-model="form.zyfw" placeholder="请输入执业范围" />
        </el-form-item>
        <el-form-item label="专业技术资格证书编号" prop="zyjszgzsbh">
          <el-input v-model="form.zyjszgzsbh" placeholder="请输入专业技术资格证书编号" />
        </el-form-item>
        <el-form-item label="专业技术资格证书发证日期" prop="zyjszgzsrq">
          <el-input v-model="form.zyjszgzsrq" placeholder="请输入专业技术资格证书发证日期" />
        </el-form-item>
        <el-form-item label="专业技术资格证书专业名称" prop="zyjszgzsmc">
          <el-input v-model="form.zyjszgzsmc" placeholder="请输入专业技术资格证书专业名称" />
        </el-form-item>
        <el-form-item label="专业技术资格证书资格级别" prop="zyjszgzsjb">
          <el-input v-model="form.zyjszgzsjb" placeholder="请输入专业技术资格证书资格级别" />
        </el-form-item>
        <el-form-item label="专业技术资格证书批准日期" prop="zyjszgzspzrq">
          <el-input v-model="form.zyjszgzspzrq" placeholder="请输入专业技术资格证书批准日期" />
        </el-form-item>
        <el-form-item label="专业技术资格证书签发日期" prop="zyjszgzspzqf">
          <el-input v-model="form.zyjszgzspzqf" placeholder="请输入专业技术资格证书签发日期" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
     <el-dialog title="修改" :visible.sync="updateNeighborhooCommittee" width="800px">
      <el-form ref="form" :model="remarkObj" label-width="100px">
        <el-form-item label="街道-居委">
          <el-select v-model="updateNeighborhooCommitteeObj.streetid"  placeholder="请选择" @change="setNeighborhoodCommittee3">
                <el-option
                  v-for="item in streetList"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id"
                  >
                </el-option>
              </el-select>        
               <el-select v-model="updateNeighborhooCommitteeObj.juweiId"  placeholder="请选择" v-if="updateNeighborhooCommitteeObj.streetid !=null && updateNeighborhooCommitteeObj.streetid !=undefined" clearable>
                <el-option
                  v-for="item in neighborhoodCommittee3"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id"
                  >
                </el-option>
              </el-select>      
        </el-form-item>
      </el-form>
      <el-row>
        <el-button type="primary" @click="updateJieWei">保存</el-button>
      </el-row>
    </el-dialog>
     <el-dialog :visible.sync="filesUpload" width="800px" title="上传">
      <el-upload
        class="upload-demo"
        ref="upload"
        :action="uploadExcelUrl"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :on-success="success"
        :file-list="fileList"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
      </el-upload>
      <br>
      <span style="color:blue" @click="downloadFile">下载模板</span>
      <br>
      <div style="text-align:right">
        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
      </div>
    </el-dialog>
      <el-dialog :visible.sync="tongJIShow" width="800px" title="等级统计">
        <div v-if="!isWu">
          <div>0-1级占比: {{levelObj.one}}%</div>
          <div>2-3级占比: {{levelObj.two}}%</div>
          <div>4级占比: {{levelObj.three}}%</div>
          <div>5-6级占比: {{levelObj.four}}%</div>
        </div>
        <div v-if="isWu">无</div>
    </el-dialog>
  </div>
</template>

<script>
import { listPgy, getPgy, delPgy, addPgy, updatePgy, exportPgy,getPgyLevel } from "@/api/assess/pgy";
import { listStreet } from "@/api/assess/street";
import axios from 'axios'

export default {
  name: "Pgy",
  data() {
    return {
      fileList:[],
      remarkObj:{},
       updateNeighborhooCommitteeObj:{juweiId:null,streetid:null,id:null},
      updateNeighborhooCommittee:false,
         streetList:[],
      neighborhoodCommittee:[],
            filesUpload:false,
      uploadExcelUrl: process.env.VUE_APP_BASE_URL +"/public/pgy/excel/upload",
      downloadExcelUrl: process.env.VUE_APP_BASE_URL +"/public/pgy/export",
      downloadExcelLevelUrl: process.env.VUE_APP_BASE_URL +"/public/pgy/level/export",
      // 遮罩层
      isWu:false,
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      pgyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tongJIShow:false,
      levelObj:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        zslx: null,
        leibei: null,
        ybbsm: null,
        xm: null,
        sex: null,
        zjlx: null,
        zjhm: null,
        csny: null,
        zgxl: null,
        pgypxsj: null,
        zgzsbh: null,
        zgzsfzrq: null,
        zsyxrq: null,
        gznx: null,
        gzdw: null,
        sbdw: null,
        zyzbh: null,
        zyzfzrq: null,
        zyzzcrq: null,
        zyzjzrq: null,
        zydd: null,
        ysjb: null,
        zyfw: null,
        zyjszgzsbh: null,
        zyjszgzsrq: null,
        zyjszgzsmc: null,
        zyjszgzsjb: null,
        zyjszgzspzrq: null,
        zyjszgzspzqf: null,
        bangding: null,
        juweiId: null,
        del: null,
        ab: null,
        ispsy: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bangding: [
          { required: true, message: "专业技术资格证书签发日期不能为空", trigger: "blur" }
        ],
        del: [
          { required: true, message: "专业技术资格证书签发日期不能为空", trigger: "blur" }
        ],
        ab: [
          { required: true, message: "专业技术资格证书签发日期不能为空", trigger: "blur" }
        ],
        ispsy: [
          { required: true, message: "专业技术资格证书签发日期不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getstreet();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
     setNeighborhoodCommittee3(){
      let id = this.updateNeighborhooCommitteeObj.id;
      let streetid = this.updateNeighborhooCommitteeObj.streetid;
      this.updateNeighborhooCommitteeObj = {"id":id,"streetid":streetid,juweiId:null};
      for(let i = 0;i<this.streetList.length;i++){
        if(this.streetList[i].id == this.updateNeighborhooCommitteeObj.streetid){
          this.neighborhoodCommittee3 = this.streetList[i].list;
          return;
        }
      }
    },
     submitUpload() {
        this.$refs.upload.submit();
      },
     getstreet() {
      listStreet({}).then(response => {
        this.streetList = response.rows;
      });
    },
       showUpdateNeighborhooCommittee(value){
      this.updateNeighborhooCommitteeObj = {};
      this.updateNeighborhooCommitteeObj.id = value.id;
      this.updateNeighborhooCommittee  = true;
    },
    success(){
      this.filesUpload  = false;
    },
    getList() {
      this.loading = true;
      listPgy(this.queryParams).then(response => {
        this.pgyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     updateJieWei(){
       if(this.updateNeighborhooCommitteeObj.streetid!=null){
         this.updateNeighborhooCommitteeObj.juweiId2 =this.updateNeighborhooCommitteeObj.streetid;
       }
       if(this.updateNeighborhooCommitteeObj.juweiId!=null){
         this.updateNeighborhooCommitteeObj.juweiId2 =this.updateNeighborhooCommitteeObj.juweiId2+","+this.updateNeighborhooCommitteeObj.juweiId;
       }
       this.updateNeighborhooCommitteeObj.juweiId = this.updateNeighborhooCommitteeObj.juweiId2;
       updatePgy(this.updateNeighborhooCommitteeObj).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.updateNeighborhooCommittee = false;
              this.getList();
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: "0",
        zslx: null,
        leibei: null,
        ybbsm: null,
        xm: null,
        sex: null,
        zjlx: null,
        zjhm: null,
        csny: null,
        zgxl: null,
        pgypxsj: null,
        zgzsbh: null,
        zgzsfzrq: null,
        zsyxrq: null,
        gznx: null,
        gzdw: null,
        sbdw: null,
        zyzbh: null,
        zyzfzrq: null,
        zyzzcrq: null,
        zyzjzrq: null,
        zydd: null,
        ysjb: null,
        zyfw: null,
        zyjszgzsbh: null,
        zyjszgzsrq: null,
        zyjszgzsmc: null,
        zyjszgzsjb: null,
        zyjszgzspzrq: null,
        zyjszgzspzqf: null,
        bangding: null,
        juweiId: null,
        del: null,
        ab: null,
        ispsy: null
      };
      this.resetForm("form");
    },
    tongJi(value){
      this.tongJIId = value.uid;
      if(this.tongJIId == null || this.tongJIId == undefined){
        this.tongJIShow=true;
        this.isWu  = true;
        return;
      }
      getPgyLevel(this.tongJIId).then(response => {
              this.levelObj = response.data;
              this.tongJIShow=true;
              this.isWu  = false;
      });


    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
       downloadFile(){
      //  let url = "http://pinggu-oss.oss-cn-hangzhou.aliyuncs.com/Unknown/评估员导入.xlsx"
      //   const a = document.createElement('a')
      //   a.href = url
      //   a.download = "评估员导入.xlsx" // 下载后文件名
      //   a.style.display = 'none'
      //   document.body.appendChild(a)
      //   a.click() // 点击下载
      //   document.body.removeChild(a) // 下载完成移除元素
         let url = "https://yumyoung.com/web/static/importExcel/评估员导入.xlsx"
        const a = document.createElement('a')
        a.href = url
        a.download = "评估员导入.xlsx" // 下载后文件名
        a.style.display = 'none'
        document.body.appendChild(a)
        a.click() // 点击下载
        document.body.removeChild(a) // 下载完成移除元素
    },
    excelDownload(){
      axios({
        method: 'get',
        url: this.downloadExcelUrl,
        headers: { 'Content-Type': 'application/json' },
        responseType: 'blob',
        }).then(({data}) => {
          const blob = new Blob([data])
          const fileName = '评估员导出.xlsx'
          const linkNode = document.createElement('a')

          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
      })
    },
    excelLevelDownload(){
      axios({
        method: 'get',
        url: this.downloadExcelLevelUrl,
        headers: { 'Content-Type': 'application/json' },
        responseType: 'blob',
        }).then(({data}) => {
          const blob = new Blob([data])
          const fileName = '评估员等级.xlsx'
          const linkNode = document.createElement('a')

          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPgy(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    updateIsPsy(value){
      this.$alert('确定修改吗？', '修改', {
          confirmButtonText: '确定',
          callback: action => {
            updatePgy({id:value.id,"ispsy":value.ispsy==0?1:0}).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.getList();
            });
          }
        });
    },
    jieBang(value){
      this.$alert('确定解绑吗？', '修改', {
          confirmButtonText: '确定',
          callback: action => {
            updatePgy({id:value.id,"bangding":0}).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.getList();
            });
          }
        });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePgy(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPgy(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除').then(function() {
        return delPgy(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有【请填写功能名称】数据项？').then(() => {
        this.exportLoading = true;
        return exportPgy(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>

<style  scoped>
 ::v-deep .el-form-item--mini.el-form-item{
    margin-bottom: 10px !important;
    
  }
  ::v-deep .el-form-item__label{
    /* font-size: 20px !important; */
  }
</style>